package com.clementheliou.cheliou.dal.model.city;

import java.io.Serializable;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import com.clementheliou.cheliou.dal.model.base.BaseEntity;
import com.clementheliou.cheliou.dal.model.country.Country;
import com.clementheliou.cheliou.dal.model.department.Department;

/**
 * Entity dedicated to the cities.
 * 
 * @author Clément HELIOU (clement.heliou@gmail.com)
 * @see {@link BaseEntity};
 * @see {@link Entity};
 * @see {@link Serializable};
 * @see {@link Table}.
 * @since 1.0
 */
@Entity
@Table(name = "city")
public class City extends BaseEntity implements Serializable {

	/**
	 * UID for serialization.
	 * 
	 * @author Clément HELIOU (clement.heliou@gmail.com)
	 * @since 1.0
	 */
	private static final long serialVersionUID = -5122745777646847668L;

	/**
	 * The country this city belongs to. If the {@link #department} is not null, this value is
	 * equals to {@link Department#getCountry()}.
	 * 
	 * @author Clément HELIOU (clement.heliou@gmail.com)
	 * @since 1.0
	 */
	private Country country;

	/**
	 * The department this city belongs to. May be null.
	 * 
	 * @author Clément HELIOU (clement.heliou@gmail.com)
	 * @since 1.0
	 */
	private Department department;

	/**
	 * The untranslatable name of the department.
	 * 
	 * @author Clément HELIOU (clement.heliou@gmail.com)
	 * @since 1.0
	 */
	private String name;

	/**
	 * The zip code of this city.
	 * 
	 * @author Clément HELIOU (clement.heliou@gmail.com)
	 * @since 1.0
	 */
	private String zipCode;

	/*
	 * Getters & setters.
	 */

	@GeneratedValue(generator = "seq_city")
	@Id
	@SequenceGenerator(name = "seq_city", sequenceName = "seq_city")
	public Integer getId() {
		return id;
	}

	@JoinColumn(name = "countryid", nullable = false)
	@ManyToOne
	@NotNull
	public Country getCountry() {
		return country;
	}

	public void setCountry(Country country) {
		this.country = country;
	}

	@JoinColumn(name = "departmentid", nullable = true)
	@ManyToOne
	public Department getDepartment() {
		return department;
	}

	public void setDepartment(Department department) {
		this.department = department;
	}

	@Basic(optional = false)
	@Column(length = 100, nullable = false)
	@NotNull
	@Size(max = 100)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Basic(optional = false)
	@Column(length = 10, nullable = false)
	@NotNull
	@Size(max = 10)
	public String getZipCode() {
		return zipCode;
	}

	public void setZipCode(String zipCode) {
		this.zipCode = zipCode;
	}

}
